class code2 {
    //快乐数
    public boolean isHappy(int n) {
        //快慢指针
        int fast = Happy(Happy(n));
        int slow = Happy(n);
        while(fast != slow) {
            fast = Happy(Happy(fast));
            slow = Happy(slow);
        }
        if(fast == slow && fast==1) {
            return true;
        }
        return false;
    }

    public int Happy(int n) {
        int ret = 0;
        while(n!=0) {
            ret += ((n%10)*(n%10));
            n/=10;
        }
        return ret;
    }
}